<?php

/**
 * Controls the functtionality  for Templates provided through the presentation layer (view)
 * to the user
 * The actions were created based on the tutorial of CakePHP Cookbook
 * http://book.cakephp.org/2.0/_downloads/en/CakePHPCookbook.pdf
 * 
 * PHP5
 * 
 * @package Controller.TemplatesController
 */
class TemplatesController extends AppController{
    
    public $helpers = array('Html', 'Form');
    public $components = array('Session');  
    var $templates;
    
    public function index(){
        $templates = $this->Template->find('all');
        $this->set('templates', $templates);
    }
    
    /**
     * Create survey action
     * @return Redirection to edit survey page
     */
    public function create($web_survey_id) {
        $this->Template->create();
        $this->Template->set('web_survey_id', $web_survey_id);
        debug('websurvey id ' . $this->Template->WebSurvey->id);
        debug('websurvey id ' . $web_survey_id);
        $this->Template->saveAll();
        return $this->redirect(array('controller'=>'WebSurveys', 'action' => 'edit', $web_survey_id, '-1'));
    }
}

